import random

from Common.basepage import BasePage
from PageLocators.PlayerPage_locator import PlayerPageLocator as loc
import re
from Common.handle_log import do_log
import time
from Common.connect_to_device import d_one, d_two


class PlayerPage(BasePage):
    def click_play(self):
        self.click_element(loc.play_loc, "点击播放或暂停")

    def click_next(self):
        self.click_element(loc.next_loc, "点击下一集")

    def click_rate(self):
        self.click_element(loc.rate_loc, "点击倍速")
        # self.click_point(1788, 875, "点击倍速")

    def click_random_schedule(self):
        # {"x":136,"y":841,"width":1652,"height":22}
        # seek_bounds = self.get_element_attribute(loc.seek_loc, "bounds", "播放器页面_获取进度条的坐标尺寸")
        # lx, ly, rx, ry = seek_bounds['left'], seek_bounds['top'], seek_bounds['right'], seek_bounds['bottom']
        # seek_center_x, seek_center_y = self.get_ele_center(loc.seek_loc, "播放器页面_获取进度条中心位置坐标")
        # width = rx - lx
        # click_x = lx + random.randint(10, width)
        # click_y = seek_center_y
        # self.click_point(click_x, click_y, "播放器页面_点击随机进度")
        click_x = 136 + random.randint(10, 136 + 1652)
        click_y = 841 + 11
        self.click_point(click_x, click_y, "点击随机进度")

    def click_back(self):
        # self.click_element(loc.back_loc, "点击返回")
        self.click_point(27, 140, "点击返回")
        # self.press_key("back")

    def click_back_third(self):
        self.click_element(loc.back_loc, "点击返回")
        # self.click_point(27, 140, "点击返回")
        # self.press_key("back")


if __name__ == '__main__':
    # MainPage().move_focus_to_item("应用")
    PlayerPage(device="d_one").click_back()
    # PlayerPage().click_point(1788, 875, "点击")
    pass
